import 'package:flutter/material.dart';
import 'package:jpush_flutter/jpush_flutter.dart';

class JPushService {
  static void jPushInit() {
    JPush jPush = JPush();

    jPush.setup(
      appKey: '1cddba04b062f330428d8f1f',
      channel: "theChannel",
      production: false,
      debug: true,
    );

    jPush.addEventHandler(
      onReceiveNotification: (Map<String, dynamic> message) async {
        print("收到消息: ${message['aps']['alert']}");
      },
      onOpenNotification: (Map<String, dynamic> message) async {
        debugPrint(message.toString());
        jPush.setBadge(0);
      },
    );
    jPush.applyPushAuthority(
      const NotificationSettingsIOS(sound: true, alert: true, badge: true),
    );
  }
}
